<!DOCTYPE html>
<html lang="en">
<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title>签到</title>
    <link rel="stylesheet" href="/sign/bootstrap.css">
    <link rel="stylesheet" href="/sign/style.css">
    <link rel="stylesheet" href="/sign/qiandao_style.css">
    <script src="/js/bootstrap/js/bootstrap.js"></script>
    <meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <link rel="stylesheet" href="/js/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="/js/plugins/dialog/dialog.css"/>
    <script src="/js/jquery/jquery.min.js"></script>
    <link rel="stylesheet" href="/css/font/css/font-awesome.min.css"/>
    <link rel="stylesheet" href="/css/reset.css"/>
    <link rel="stylesheet" href="/css/myProfiles.css"/>
    <script src="/js/plugins/jrender/jrender.js"></script>
    <script src="/js/bootstrap/js/bootstrap.min.js"></script>
    <script src="/js/plugins/dialog/dialog.min.js"></script>
</head>

<body>

<div class="nav-search">
    <a href="/mine/profiles.html">
        <span><i class="fa fa-angle-left fa-2x"></i></span>
    </a>
</div>


<hr/>
<div class="container">
    <div class="row">
        <div class="col-xs-12 clearPadding">
            <div class=""><img src="/sign/qdBanner.jpg" class="img-responsive"></div>

            <div class="calendar">
                <div class="calenbox">
                    <div id="calendar">
                        <div class="sign_main" id="sign_layer">
                            <div class="sign_succ_calendar_title">
                                <div class="calendar_month_next">下月</div>
                                <div class="calendar_month_prev">上月</div>
                                <div class="calendar_month_span">2018年11月</div>
                            </div>
                            <div class="sign" id="sign_cal">
                                <table>
                                    <tbody>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td>1</td>
                                        <td>2</td>
                                        <td>3</td>
                                    </tr>
                                    <tr>
                                        <td>4</td>
                                        <td>5</td>
                                        <td>6</td>
                                        <td>7</td>
                                        <td>8</td>
                                        <td>9</td>
                                        <td class="on">10</td>
                                    </tr>
                                    <tr>
                                        <td class="on">11</td>
                                        <td class="on">12</td>
                                        <td class="on">13</td>
                                        <td>14</td>
                                        <td>15</td>
                                        <td>16</td>
                                        <td>17</td>
                                    </tr>
                                    <tr>
                                        <td>18</td>
                                        <td>19</td>
                                        <td>20</td>
                                        <td>21</td>
                                        <td>22</td>
                                        <td>23</td>
                                        <td>24</td>
                                    </tr>
                                    <tr>
                                        <td>25</td>
                                        <td>26</td>
                                        <td>27</td>
                                        <td>28</td>
                                        <td>29</td>
                                        <td>30</td>
                                        <td></td>
                                    </tr>
                                    <tr>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                        <td></td>
                                    </tr>
                                    </tbody>
                                </table>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="text-center">
                    <button class="btn btn-qiandao" onclick="signIn()">马上签到</button>
                </div>
            </div>

        </div>
    </div>
</div>

<div class="maskbox"></div>
<div class="qdbox" id="signMassage">
    <div class="text-center text-green font18"><strong>签到成功！</strong></div>
    <div class="text-center text-green pt10">您已连续签到&nbsp;<span class="text-green" id="signCount"></span>&nbsp;天</div>
    <div class="text-center text-green pt10">积分+10</div>
    <div class="text-center ptb15 lottery"><img src="/sign/shop.png" style="width:125px;margin-left:20px;"></div>
    <div class="text-center lottery">
        <button class="btn btn-lottery">去商城兑换</button>
    </div>
</div>
<script src="/sign/calendar.js"></script>
<!--<script src="/sign/jquery-1.js"></script>-->

<script>
    // 全局用户签到信息
    var data;

    // 点击签到的事件
    function signIn() {
        // 发送异步请求进行签到功能
        // 获取用户本地缓存信息
        var user = JSON.parse(sessionStorage.getItem("user"));
        $.get("/signs/" + user.id + "/signToday", function (data) {
            if (data.success) {
                // 获取连续签到天数
                var signCount = data.data.signCount
                // 渲染
                $("#signCount").html(signCount);
                // 没有达到连续签到三天不能抽奖
                if (signCount < 3) {
                    $(document).dialog({
                        type : 'confirm',
                        closeBtnShow: true,
                        content: '签到成功!积分+10!马上到商城兑换礼品',
                        onClickConfirmBtn: function(){
                            location.href = "/mine/index.html";
                        },
                        onClickCancelBtn : function(){
                            location.href = "/mine/profiles.html";
                        }
                    });
                } else {
                    $(document).dialog({
                        type : 'confirm',
                        closeBtnShow: true,
                        content: '连续签到三天!积分+20!马上到商城兑换礼品',
                        onClickConfirmBtn: function(){
                            location.href = "/mine/index.html";
                        },
                        onClickCancelBtn : function(){
                            location.href = "/mine/profiles.html";
                        }
                    });
                }
            } else {
                $(document).dialog({
                    type : 'confirm',
                    closeBtnShow: true,
                    content: '您今日已签到!马上到商城兑换礼品!',
                    onClickConfirmBtn: function(){
                        location.href = "/mine/index.html";
                    },
                    onClickCancelBtn : function(){
                        location.href = "/mine/profiles.html";
                    }
                });
            }
            data = data.data;
        });

        // $(".maskbox").fadeIn();
        // $(".qdbox").fadeIn();
        // $(".maskbox").height($(document).height());
    }


    $(".maskbox").click(function () {
        $(".maskbox").fadeOut();
        $(".qdbox").fadeOut();
    });


    $(function () {
        // var signList = [{"signDay": "10"}, {"signDay": "11"}, {"signDay": "12"}, {"signDay": "13"}];
        var signList = [];
        var user = JSON.parse(sessionStorage.getItem("user"));
        // 页面加载完毕发送请求查询用户的签到信息
        $.get("/signs/" + user.id + "/credits", function (data) {
            if (data.success) {
                // 连续签到次数
                var signCount = data.data.signCount;
                // 最近签到日期
                var signTime = parseInt(data.data.signTime);
                for (var i = 0; i < signCount; i++) {
                    signList[i] = {"signDay": signTime--};
                }
                // 调用日期回显函数
                calUtil.init(signList);
            }
            // reviewSignTime(data.data);
        });

    });


    // 处理签到时间回显的方法
    function reviewSignTime(data) {
        var signList = [];
        if (data.success) {
            // 连续签到次数
            var signCount = data.data.signCount;
            // 最近签到日期
            var signTime = parseInt(data.data.signTime);
            for (var i = 0; i < signCount; i++) {
                signList[i] = {"signDay": signTime--};
            }
            // 调用日期回显函数
            calUtil.init(signList);
        }
    }

    // 页面加载完毕给去商城按钮绑定点击事件
    $(function () {
        $(".btn-lottery").click(function () {
            window.location.href = "/mine/profiles.html";
        })
    })
</script>
</body>
</html>